package com.shuyun.java8;

import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2021/6/22 10:28 上午
 */
public class Filter<T> {

    /**
     * 过滤出符合条件的数据集
     * @param list
     * @param bb
     * @param <T>
     * @return
     */
    public static <T> List<T> filter(List<T> list, BooleanFunctionInterface bb) {
        if (list == null) {
            return Collections.emptyList();
        }
        return list.stream().filter(record -> bb.test(record)).collect(Collectors.toList());
    }

    public static <T> List<T> filter2(List<T> list, Predicate predicate) {
        if (list == null) {
            return Collections.emptyList();
        }
        return list.stream().filter(record -> predicate.test(record)).collect(Collectors.toList());
    }

}
